<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%
String username = (String) session.getAttribute("username");
if(username==null){
    out.print("Please login first! redirecting to Login...");
    response.setHeader("Refresh","2;URL=login.jsp");
}
%>

<html>
<head>
        <input type="hidden" id="msg" value="${msg}"/> 
        <%
        session.removeAttribute("msg");
        %>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Manage Account</title>
        <script type="text/javascript">
		window.onload = function () {
			document.getElementById("msg_label").innerHTML=document.getElementById("msg").value;            
			}
		function isEmpty(){
            var flag=false;
            var patrn1=/^(\w){1,25}$/;
            if((document.getElementById("old_password").value)==""){
                alert("old password is empty!");
                return false;
            }
            else if(!patrn1.exec(document.getElementById("old_password").value)){
            	alert("old password format error or too long!");
            	return false;
            }
            else if((document.getElementById("new_password").value)==""){
                alert("new password is empty!");
              return false;  
            } 
            else if(!patrn1.exec(document.getElementById("new_password").value)){
            	alert("new password can't be too long!");
            	return false;
            }
            else if((document.getElementById("new_password").value)!=(document.getElementById("passwordconfirm").value)){
                alert("password confirm is different from password!");
              return false;  
            } 
            else return true;
            }
         
        </script>
        <link rel="stylesheet" type="text/css" href="main.css">
    </head>
    
    <% String name=(String)session.getAttribute("username");

	if(name==null){
    	out.print("Please login first! redirecting to Login...");
    	response.setHeader("Refresh","1;URL=login.jsp");
	}
	else{
	%>
    
    <body>
    	<h3>Modify Password</h3>
        <h4>Please fill the required information:</h4>
        <label id="msg_label"></label><br>
        <form action="ManageAccount" name="manageAccount" method="post" onsubmit="return isEmpty()">
            <table>
                <tr><td>Username:</td><td><%=username%></td><td></td></tr>
                <tr><td>Old Password:</td><td><input type="password" name="old_password" id="old_password" ></td><td></td></tr>
                <tr><td>New Password:</td><td><input type="password" name="new_password" id="new_password" ></td><td></td></tr>
                <tr><td>Password Confirm:</td><td><input type="password" id="passwordconfirm"></td><td></td></tr>
            </table>
        <input type="submit" value="submit">
        </form>
    </body>
    
    <% } %>
    
</html>